﻿<UserControl x:Class="myCollections.UserControls.Common.UcCoverFlow"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:converters="clr-namespace:myCollections.Utils"
             xmlns:effects="clr-namespace:myCollections.Controls.CustomEffects"
             xmlns:common="clr-namespace:myCollections.UserControls.Common"
             xmlns:fl="clr-namespace:SStuff.FlowControls;assembly=SStuff.FlowControls"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.InputBindings>
        <KeyBinding Command="common:Commands.EditItem" Gesture="CTRL+E"></KeyBinding>
        <KeyBinding Command="common:Commands.PlayItem" Gesture="CTRL+P"></KeyBinding>
        <KeyBinding Command="common:Commands.DeleteItem" Gesture="CTRL+D"></KeyBinding>
    </UserControl.InputBindings>
    <UserControl.CommandBindings>
        <CommandBinding Command="common:Commands.EditItem"  Executed="OnEdit" />
        <CommandBinding Command="common:Commands.PlayItem"  Executed="OnPlay"  />
        <CommandBinding Command="common:Commands.DeleteItem"  Executed="OnDelete"  />
    </UserControl.CommandBindings>
    <UserControl.Resources>
        <Style x:Key="searchResultItemFocusVisualStyle">
            <Setter Property="Control.Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Control}">
                        <Rectangle Margin="0,-2" RadiusX="4" RadiusY="4" StrokeThickness="1" Stroke="DarkGray" StrokeDashArray="1 2" />
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <converters:ByteArrayToBitmapImageConverter x:Key="byteArrayToBitmapImageConverter" />
        <DataTemplate x:Key="ImageFromFile">
            <Control>
                <Control.Template>
                    <ControlTemplate>
                        <Border Padding="3" Background="{DynamicResource BorderColor}" 
                                CornerRadius="6"  BorderThickness="1" x:Name="bd" Margin="5" 
                                Focusable="True" FocusVisualStyle="{StaticResource searchResultItemFocusVisualStyle}">
                            <Grid>
                                <Image IsHitTestVisible="True" 
                                       Source="{Binding Path=Cover, Converter={StaticResource byteArrayToBitmapImageConverter}}" 
                                       ToolTip="{Binding Path=Name}"  />
                                <Button x:Name="btnEdit" Visibility="Collapsed" VerticalAlignment="Bottom" HorizontalAlignment="Right"
                                         ToolTip="Click to edit" Command="common:Commands.EditItem" CommandParameter="{Binding}">
                                    <Button.Template>
                                        <ControlTemplate>
                                            <Border Padding="2" CornerRadius="6" Background="LightGray" BorderBrush="Black" BorderThickness="1">
                                                <Image Source="/myCollections;component/Images/edit.png" Height="16" Width="16" >
                                                    <Image.Effect>
                                                        <effects:GreyscaleEffect />
                                                    </Image.Effect>
                                                </Image>
                                            </Border>
                                        </ControlTemplate>
                                    </Button.Template>
                                </Button>
                                <Button x:Name="btnPlay" Visibility="Collapsed" VerticalAlignment="Bottom" HorizontalAlignment="Left"
                                         ToolTip="Click to play" Command="common:Commands.PlayItem" CommandParameter="{Binding}">
                                    <Button.Template>
                                        <ControlTemplate>
                                            <Border Padding="2" CornerRadius="6" Background="LightGray" BorderBrush="Black" BorderThickness="1">
                                                <Image Source="/myCollections;component/Images/Play.png" Height="16" Width="16" >
                                                    <Image.Effect>
                                                        <effects:GreyscaleEffect />
                                                    </Image.Effect>
                                                </Image>
                                            </Border>
                                        </ControlTemplate>
                                    </Button.Template>
                                </Button>
                                <Button x:Name="btnDelete" Visibility="Collapsed" VerticalAlignment="Top" HorizontalAlignment="Right"
                                         ToolTip="Click to delete" Command="common:Commands.DeleteItem" CommandParameter="{Binding}">
                                    <Button.Template>
                                        <ControlTemplate>
                                            <Border Padding="2" CornerRadius="6" Background="LightGray" BorderBrush="Black" BorderThickness="1">
                                                <Image Source="/myCollections;component/Images/delete2.png" Height="16" Width="16" >
                                                    <Image.Effect>
                                                        <effects:GreyscaleEffect />
                                                    </Image.Effect>
                                                </Image>
                                            </Border>
                                        </ControlTemplate>
                                    </Button.Template>
                                </Button>
                            </Grid>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="True">
                                <Setter TargetName="bd" Property="Background" Value="{DynamicResource MouseOverColor}" />
                                <Setter TargetName="bd" Property="BorderBrush" Value="Black" />
                                <Setter TargetName="btnEdit" Property="Visibility" Value="Visible" />
                                <Setter TargetName="btnDelete" Property="Visibility" Value="Visible" />
                                <Setter TargetName="btnPlay" Property="Visibility" Value="Visible" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Control.Template>
            </Control>
        </DataTemplate>
    </UserControl.Resources>
    <fl:FlowItemsControl2D Margin="50" ItemsSource="{Binding}" ItemTemplate="{StaticResource ImageFromFile}"
                           Background="{x:Null}" BorderBrush="{x:Null}" FocusVisualStyle="{x:Null}"
                           MouseWheel="CoverFlow_MouseWheel"
                           MouseDoubleClick="CoverFlow_MouseDoubleClick"
                           Name="CoverFlow">
        <fl:FlowItemsControl2D.ContextMenu>
            <ContextMenu Background="{DynamicResource ToolbarBackGroundColor}">
                <ContextMenu.Effect>
                    <DropShadowEffect/>
                </ContextMenu.Effect>
                <MenuItem Name="mniOpenSelected" Header="{DynamicResource Play}" 
                          Click="mniOpenSelected_Click"
                           IsCheckable="False" >
                    <MenuItem.Icon>
                        <Image Visibility="Collapsed" />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Name="mniManualUpdate" Header="{DynamicResource ManualUpdate}" Click="mniManualUpdate_Click"  IsCheckable="False">
                    <MenuItem.Icon>
                        <Image Visibility="Collapsed" />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Name="mniUpdateSelected" Header="{DynamicResource UpdateFromWeb}" 
                                 Click="mniUpdateSelected_Click"  IsCheckable="False">
                    <MenuItem.Icon>
                        <Image Visibility="Collapsed" />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Name="mniDeleteSelected" Header="{DynamicResource Delete}" 
                                 Click="mniDeleteSelected_Click"  IsCheckable="False">
                    <MenuItem.Icon>
                        <Image Visibility="Collapsed" />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Name="mniMarkToDeleteSelected" Header="{DynamicResource ToBeDeleted}" 
                                 Click="mniMarkToDeleteSelected_Click"  IsCheckable="False">
                    <MenuItem.Icon>
                        <Image Width="30" Source="pack://application:,,,/myCollections;component/Images/Delete.png" />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Header="{DynamicResource SetNotComplete}" IsEnabled="True" Name="mniCompleteFalse" 
                                  Click="mniCompleteFalse_Click"  IsCheckable="False">
                    <MenuItem.Icon>
                        <Image Visibility="Collapsed" />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Header="{DynamicResource LoanTo}" IsEnabled="True" Name="mniLoanTo" 
                                  Click="mniLoanTo_Click"  IsCheckable="False">
                    <MenuItem.Icon>
                        <Image Visibility="Collapsed" />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Header="{DynamicResource LoanInfo}" Name="mniLoanInfo" 
                                  Click="mniLoanInfo_Click"  IsCheckable="False" Visibility="Collapsed">
                    <MenuItem.Icon>
                        <Image Visibility="Collapsed" />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Header="{DynamicResource SetBack}" Name="mniSetBack" 
                                  Click="mniSetBack_Click"  IsCheckable="False" Visibility="Collapsed">
                    <MenuItem.Icon>
                        <Image Visibility="Collapsed" />
                    </MenuItem.Icon>
                </MenuItem>
                <MenuItem Header="{DynamicResource GenerateTvix}" Name="mniGenerateTvix" 
                                  Click="mniGenerateTvix_Click"  IsCheckable="False">
                    <MenuItem.Icon>
                        <Image Visibility="Collapsed" />
                    </MenuItem.Icon>
                </MenuItem>
            </ContextMenu>
        </fl:FlowItemsControl2D.ContextMenu>
    </fl:FlowItemsControl2D>
</UserControl>
